﻿@namespace MudBlazor.UnitTests.TestComponents

<MudDropContainer T="DropItem" Items="_items" ItemsSelector="@((item,dropzone) => item.Selector == dropzone)" ItemDropped="ItemUpdated" Class="d-flex flex-wrap flex-grow-1" ItemsClassSelector="GetItemClass">
    <ChildContent>
        @for (int i = 1; i < 4; i++) 
         {
             var dropzone = i.ToString();
             <MudPaper Class="ma-4 flex-grow-1 ">
                 <MudList Clickable="true" Class="d-flex flex-column mud-height-full">
                     <MudListSubheader>Drop Zone @dropzone</MudListSubheader>
                    <MudDropZone T="DropItem" Identifier="@dropzone" Class="@($"flex-grow-1 dropzone-{dropzone}")" AllowReorder="true" />
                 </MudList>
             </MudPaper>
         }
    </ChildContent>
    <ItemRenderer>
        <MudListItem Text="@context.Name"/>
    </ItemRenderer>
</MudDropContainer>


@code {
    private void ItemUpdated(MudItemDropInfo<DropItem> dropItem)
    {
        dropItem.Item.Selector = dropItem.DropzoneIdentifier;
        IndexHistory.Add(dropItem.IndexInZone);
    }

    public List<int> IndexHistory { get; set; } = new();


    private List<DropItem> _items = new()
    {
        new DropItem(){ Name = "Item 1", Selector = "1" },
        new DropItem(){ Name = "Item 2", Selector = "1" },
        new DropItem(){ Name = "Item 3", Selector = "1" },
        new DropItem(){ Name = "Item 4", Selector = "1" },
        new DropItem(){ Name = "Item 5", Selector = "2" },
        new DropItem(){ Name = "Item 6", Selector = "2" },
    };

    public class DropItem
    {
        public string Name { get; init; }
        public string Selector { get; set; }
    }

    private string GetItemClass(DropItem item, String dropzoneid)
    {
        if (dropzoneid == "1") return "mud-theme-primary";
        else if (dropzoneid == "2") return "mud-theme-secondary";
        else if (dropzoneid == "3") return "mud-theme-tertiary ";
        else return string.Empty;
    }

}